package util;

import javax.imageio.ImageIO;
import java.awt.*;
import java.io.File;
import java.io.IOException;

/**
 * @author zhongwen
 * @description 处理并获取图片的工具类
 * @date 2021-12-08 21:48
 */
public class ImageUtils {
    /**
     * @param path 图片的文件名
     */
    public static Image getImage(String path){
        Image ans = null;
        try {
            ans = ImageIO.read(new File("images/" + path));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return ans;
    }
    /**
     * @param path 图片的文件名
     * @param width 处理后图片的宽度
     * @param height 处理后图片的高度
     */
    public static Image getImage(String path, int width, int height){
        Image ans = null;
        try {
            ans = ImageIO.read(new File("images/" + path));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return ans.getScaledInstance(width, height, Image.SCALE_AREA_AVERAGING);
    }
}
